{% block sw_bulk_edit_product %}
<sw-page
    :class="{
        'sw-bulk-edit-product': true,
        'is--variant': isChild,
    }"
>
    {% block sw_bulk_edit_product_search_bar %}
    <template #search-bar>
        <sw-search-bar />
    </template>
    {% endblock %}

    {% block sw_bulk_edit_product_smart_bar_back %}
    <template #smart-bar-back>
        <router-link
            v-if="isChild"
            class="smart-bar__back-btn"
            :to="{ name: 'sw.product.detail.variants', params: { id: $route.params.parentId } }"
            :style="{ 'color': $route.meta.$module?.color }"
        >
            <mt-icon
                name="regular-chevron-left"
                size="16px"
            />
        </router-link>
    </template>
    {% endblock %}

    {% block sw_bulk_edit_product_smart_bar_header %}
    <template #smart-bar-header>
        {% block sw_bulk_edit_product_smart_bar_header_title %}
        <h2>
            {{ isChild
            ? $tc('sw-bulk-edit.variant.textTitle', { variantTotal: selectedIds.length }, selectedIds.length)
            : $tc('sw-bulk-edit.product.textTitle', { productTotal: selectedIds.length }, selectedIds.length)
            }}
        </h2>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_bulk_edit_product_content_language_switch %}
    <template #language-switch>
        <sw-language-switch @on-change="onChangeLanguage" />
    </template>
    {% endblock %}

    {% block sw_bulk_edit_product_content_smart_bar_actions %}
    <template #smart-bar-actions>
        {% block sw_bulk_edit_product_actions_save %}
        <sw-button-process
            class="sw-bulk-edit-product__save-action"
            variant="primary"
            :is-loading="isLoading"
            :process-success="isSaveSuccessful"
            :disabled="isLoading || !hasSelectedChanges || undefined"
            @click="openModal"
        >
            {{ $tc('sw-bulk-edit.applyChanges') }}
        </sw-button-process>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_bulk_edit_product_content %}
    <template #content>
        <sw-card-view v-if="selectedIds.length > 0 && isLoadedData">
            {% block sw_bulk_edit_product_content_inheritance_card %}
            <mt-card
                v-if="isChild"
                class="sw-bulk-edit-product__inheritance"
                position-identifier="sw-bulk-edit-product-inheritance"
            >
                {% block sw_bulk_edit_product_content_inheritance_alert %}
                <mt-banner variant="inherited">
                    {{ $tc('sw-bulk-edit.product.alertInheritance.message') }}
                </mt-banner>
                {% endblock %}
            </mt-card>
            {% endblock %}
            <mt-card
                v-if="restrictedFields.length"
                class="sw-bulk-edit-product__restricted-fields"
                position-identifier="sw-bulk-edit-product-restricted-fields"
            >
                <mt-banner
                    :title="$tc('sw-bulk-edit.product.alertRestrictedFields.title')"
                    variant="attention"
                >
                    <span v-html="$tc('sw-bulk-edit.product.alertRestrictedFields.message')"></span>
                    <ul>
                        <li
                            v-for="(restrictedField, index) in restrictedFields"
                            :key="index"
                        >
                            {{ $tc(`sw-bulk-edit.product.alertRestrictedFields.${restrictedField}`) }}
                        </li>
                    </ul>
                </mt-banner>
            </mt-card>

            {% block sw_bulk_edit_product_content_gereral_information_card %}
            <mt-card
                class="sw-bulk-edit-product-base__info"
                position-identifier="sw-bulk-edit-product-info"
                :title="$tc('sw-bulk-edit.product.generalInformation.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_gereral_information %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="generalFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_prices_card %}
            <mt-card
                class="sw-bulk-edit-product-base__prices"
                position-identifier="sw-bulk-edit-product-prices"
                :title="$tc('sw-bulk-edit.product.prices.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_prices %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="pricesFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @change-value="onChangePrices"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_advanced_prices_card %}
            <mt-card
                class="sw-bulk-edit-product-base__advanced-prices"
                position-identifier="sw-bulk-edit-product-advanced-prices"
                :title="$tc('sw-bulk-edit.product.advancedPrices.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_advanced_prices %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="advancedPricesFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                >
                    <template #valueFieldWithBoxType="{ formField, entity, index }">
                        <sw-inheritance-switch
                            v-if="isChild"
                            :is-inherited="bulkEditProduct[formField.name].isInherited"
                            @inheritance-restore="onInheritanceRestore(formField)"
                            @inheritance-remove="onInheritanceRemove(formField)"
                        />

                        <a
                            v-if="['add', 'overwrite'].includes(bulkEditProduct[formField.name].type)"
                            :class="{ 'is--disabled': !!bulkEditProduct[formField.name].isInherited }"
                            class="sw-card__quick-link"
                            role="link"
                            tabindex="0"
                            @click="displayAdvancePricesModal = true"
                            @keydown.enter="displayAdvancePricesModal = true"
                        >
                            {{ $tc('sw-bulk-edit.product.advancedPrices.newAdvancedPrices', { count: entity[formField.name] ? Object.keys(priceRuleGroups).length : 0 }, 0) }}
                            <mt-icon
                                name="regular-long-arrow-right"
                                size="16px"
                            />
                        </a>

                        {% block sw_bulk_edit_product_content_advanced_prices_rule_selection %}
                        <sw-entity-multi-select
                            v-else-if="bulkEditProduct[formField.name].type === 'remove'"
                            class="sw-bulk-edit-product-base__advanced-prices-selection"
                            :placeholder="$tc('sw-bulk-edit.product.advancedPrices.selectRule')"
                            :criteria="ruleCriteria"
                            entity-name="rule"
                            :entity-collection="!!bulkEditProduct[formField.name].isInherited ? [] : entity[formField.name]"
                            :disabled="!!bulkEditProduct[formField.name].isInherited || undefined"
                            @update:entity-collection="onRuleChange"
                        >
                            <template #selection-label-property="{ item }">
                                {{ item.ruleName }}
                            </template>

                            <template #result-item="{ item, index, labelProperty, isSelected, addItem, getKey }">
                                <sw-select-result
                                    :selected="isSelected(item)"
                                    :disabled="!!priceRuleGroups[item.id] || undefined"
                                    v-bind="{ item, index }"
                                    @item-select="addItem"
                                >
                                    {{ getKey(item,labelProperty) || getKey(item, `translated.${labelProperty}`) }}
                                </sw-select-result>
                            </template>
                        </sw-entity-multi-select>
                        {% endblock %}
                    </template>
                </sw-bulk-edit-change-type-field-renderer>
                {% endblock %}

                {% block sw_bulk_edit_product_content_advanced_prices_modal %}
                <sw-modal
                    v-if="displayAdvancePricesModal"
                    class="sw-bulk-edit-product-content-advanced-prices-modal"
                    variant="large"
                    :title="$tc('sw-bulk-edit.product.advancedPrices.cardTitle')"
                    @modal-close="displayAdvancePricesModal = false"
                >
                    <sw-product-detail-context-prices
                        :is-set-default-price="true"
                        :can-set-loading-rules="false"
                    />

                    {% block sw_bulk_edit_product_content_advanced_prices_modal_footer %}
                    <template #modal-footer>
                        <slot name="sw-bulk-edit-modal-cancel">
                            <mt-button
                                size="small"
                                variant="secondary"
                                @click="displayAdvancePricesModal = false"
                            >
                                {{ $tc('global.default.close') }}
                            </mt-button>
                        </slot>
                    </template>
                    {% endblock %}
                </sw-modal>
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_property_card %}
            <mt-card
                class="sw-bulk-edit-product-base__property"
                position-identifier="sw-bulk-edit-product-property"
                :title="$tc('sw-bulk-edit.product.property.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_property %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="propertyFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_deliverability_card %}
            <mt-card
                class="sw-bulk-edit-product-base__deliverability"
                position-identifier="sw-bulk-edit-product-deliverability"
                :title="$tc('sw-bulk-edit.product.deliverability.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_deliverability %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="deliverabilityFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_assignments_card %}
            <mt-card
                class="sw-bulk-edit-product-base__assignment"
                position-identifier="sw-bulk-edit-product-assignment"
                :title="$tc('sw-bulk-edit.product.assignment.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_assignments %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="assignmentFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_media_card %}
            <mt-card
                class="sw-bulk-edit-product-base__media"
                position-identifier="sw-bulk-edit-product-media"
                :title="$tc('sw-bulk-edit.product.media.cardTitle')"
            >
                {% block media %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="mediaFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_labelling_card %}
            <mt-card
                class="sw-bulk-edit-product-base__labelling"
                position-identifier="sw-bulk-edit-product-labelling"
                :title="$tc('sw-bulk-edit.product.labelling.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_labelling %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="labellingFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_seo_card %}
            <mt-card
                class="sw-bulk-edit-product-base__seo"
                position-identifier="sw-bulk-edit-product-seo"
                :title="$tc('sw-bulk-edit.product.seo.cardTitle')"
            >
                {% block sw_bulk_edit_product_content_seo %}
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="seoFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
                {% endblock %}
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_meansures_packaging_card %}
            <mt-card
                class="sw-bulk-edit-product-base__measures"
                position-identifier="sw-bulk-edit-product-measures"
                :title="$tc('sw-bulk-edit.product.measuresAndPackaging.cardTitle')"
            >
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="measuresPackagingFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_essential_card %}
            <mt-card
                class="sw-bulk-edit-product-base___essential"
                position-identifier="sw-bulk-edit-product-essential"
                :title="$tc('sw-bulk-edit.product.featureSets.cardTitle')"
            >
                <sw-bulk-edit-change-type-field-renderer
                    :form-fields="essentialCharacteristicsFormFields"
                    :bulk-edit-data="bulkEditProduct"
                    :entity="product"
                    @inheritance-restore="onInheritanceRestore"
                    @inheritance-remove="onInheritanceRemove"
                />
            </mt-card>
            {% endblock %}

            {% block sw_bulk_edit_product_content_meansures_custom_field_card %}
            <mt-card
                v-if="customFieldSets.length > 0"
                class="sw-bulk-edit-product-base__custom_fields"
                position-identifier="sw-bulk-edit-product-custom-fields"
                :title="$tc('sw-bulk-edit.product.customFields.cardTitle')"
            >
                <sw-bulk-edit-custom-fields
                    class="sw-bulk-edit__custom-fields"
                    :sets="customFieldSets"
                    :entity="product"
                    :parent-entity="parentProduct"
                    @change="onCustomFieldsChange"
                />
            </mt-card>
            {% endblock %}
        </sw-card-view>
        <sw-empty-state
            v-if="!isLoading && selectedIds.length == 0"
            :title="$tc('sw-bulk-edit.product.messageEmptyTitle')"
            :subline="$tc('sw-bulk-edit.product.messageEmptySubline')"
        />

        {% block sw_bulk_edit_product_save_modal %}
        <router-view
            v-slot="{ Component }"
        >
            <component
                :is="Component"
                :item-total="selectedIds.length"
                :is-loading="isLoading"
                :process-status="processStatus"
                @modal-close="closeModal"
                @bulk-save="onSave"
            />
        </router-view>
        {% endblock %}
    </template>
    {% endblock %}
</sw-page>
{% endblock %}
